package com.ge.med.cchelper.form;


import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

import com.ge.med.cchelper.listener.EnterListener;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class CommentForm extends org.eclipse.swt.widgets.Dialog {

	private Shell dialogShell;
	private Text text1;
	private Button button2;
	private Label label2;
	private Button button1;
	private String comments;
	private String checkType;
	private boolean isClose = false;
	/**
	* Auto-generated main method to display this 
	* org.eclipse.swt.widgets.Dialog inside a new Shell.
	*/
	public static void main(String[] args) {
		try {
			Display display = Display.getDefault();
			Shell shell = new Shell(display);
			CommentForm inst = new CommentForm(shell, SWT.NULL,"checkout");
			inst.open();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public CommentForm(Shell parent, int style,String checkType) {
		super(parent, style);
		this.checkType = checkType;
	}
	
	public void open() {
		try {
			Shell parent = getParent();
			dialogShell = new Shell(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);

			dialogShell.setLayout(new FormLayout());
			dialogShell.layout();
			dialogShell.pack();			
			dialogShell.setSize(424, 180);
			dialogShell.setText(checkType);
			{
				button2 = new Button(dialogShell, SWT.PUSH | SWT.CENTER);
				FormData button2LData = new FormData();
				button2LData.left =  new FormAttachment(0, 1000, 362);
				button2LData.top =  new FormAttachment(0, 1000, 119);
				button2LData.width = 42;
				button2LData.height = 22;
				button2.setLayoutData(button2LData);
				button2.setText("Close");
				
				Listener lis = new Listener() {
		
					public void handleEvent(Event arg0) {
						isClose=true;
						dialogShell.dispose();
					}
				};
				button2.addListener(SWT.Selection, lis);
			}
			{
				label2 = new Label(dialogShell, SWT.NONE);
				FormData label2LData = new FormData();
				label2LData.left =  new FormAttachment(0, 1000, 12);
				label2LData.top =  new FormAttachment(0, 1000, 12);
				label2LData.width = 108;
				label2LData.height = 12;
				label2.setLayoutData(label2LData);
				label2.setText("Comment:");
			}
			{
				text1 = new Text(dialogShell, SWT.MULTI | SWT.WRAP | SWT.BORDER);
				FormData text1LData = new FormData();
				text1LData.left =  new FormAttachment(0, 1000, 12);
				text1LData.top =  new FormAttachment(0, 1000, 35);
				text1LData.width = 386;
				text1LData.height = 72;
				text1.setLayoutData(text1LData);
				text1.addTraverseListener(new EnterListener());
			}
			{
				button1 = new Button(dialogShell, SWT.PUSH | SWT.CENTER);
				FormData button1LData = new FormData();
				button1LData.left =  new FormAttachment(0, 1000, 296);
				button1LData.top =  new FormAttachment(0, 1000, 119);
				button1LData.width = 54;
				button1LData.height = 22;
				button1.setLayoutData(button1LData);
				button1.setText(checkType);
				Listener lis = new Listener() {
					
					public void handleEvent(Event arg0) {
						comments = text1.getText();
						comments=comments.trim().equals("")?null:comments;
						dialogShell.dispose();
					}
				};
                button1.addListener(SWT.Selection, lis);
			}
			dialogShell.setDefaultButton(button1);
			dialogShell.setLocation(getParent().toDisplay(100, 100));
			dialogShell.open();
			Display display = dialogShell.getDisplay();
			while (!dialogShell.isDisposed()) {
				if (!display.readAndDispatch())
					display.sleep();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public String getComments(){
		return comments;
	}
	
	public boolean isClose(){
		return isClose;
	}
	
	
}
